<%-- 
	body-content=scriptless 标签内部内容不能包含JSP脚本
--%>

<%@tag import="com.dxl.common.utils.Utils"%>
<%@tag import="org.apache.log4j.Logger"%>
<%@ tag import="com.dxl.common.cache.CacheClient"%>
<%@ tag import="com.dxl.common.spring.AppCtxHolder"%>
<%@ tag body-content="scriptless" pageEncoding="UTF-8" %>
<%@ tag import="java.io.StringWriter"%>

<%@ attribute name="key" required="true" type="java.lang.String" rtexprvalue="true" %>  
<%@ attribute name="cacheSecs" required="true" type="java.lang.Integer" rtexprvalue="true" %>  
<%@ attribute name="refresh" required="false" type="java.lang.String" rtexprvalue="true" %>  

<%
	Logger LOG = Logger.getLogger("cache.tag");
	CacheClient cacheClient = AppCtxHolder.getBean(CacheClient.class);
	String body = (String) cacheClient.get(key);
	if (Utils.isNotNull(refresh) || Utils.isNull(body)) {
		LOG.info("缓存没有对应的内容，key：" + key);
		StringWriter sw = new StringWriter();
		getJspBody().invoke(sw);
		
		sw.close();
		body = sw.toString();
		cacheClient.set(key, body, cacheSecs);
	} else {
		LOG.info("缓存有对应的内容，key：" + key);
	}
	out.print(body);
%>